import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

/**
 * Applet class
 * 
 * The user interface for our .ics calendar file application
 * @author	Caroline Paulic
 * @date		August 8, 2012
 * @class	ICS 314
 */
public class Applet extends JApplet implements ActionListener{
	JLabel nameLabel = new JLabel("Name");
	JLabel timeLabel = new JLabel("Time");
	JLabel toLabel1 = new JLabel(" to ");
	JLabel colonLabel1 = new JLabel(":");
	JLabel colonLabel2 = new JLabel(":");
	JLabel timeZoneLabel = new JLabel("Time Zone");
	JLabel dateLabel = new JLabel("Date");
	JLabel slashLabel1 = new JLabel("/");
	JLabel slashLabel2 = new JLabel("/");
	JLabel toLabel2 = new JLabel(" to ");
	JLabel slashLabel3 = new JLabel("/");
	JLabel slashLabel4 = new JLabel("/");
	JLabel locationLabel = new JLabel("Location");
	JLabel descriptionLabel = new JLabel("Description");
	JLabel commentsLabel = new JLabel("Comments");
	JLabel priorityLabel = new JLabel("Priority");
	JLabel resourcesLabel = new JLabel("Resources");
	JLabel fileLabel = new JLabel("File Name");
	
	JTextField nameField = new JTextField("", 20);
	JTextField startHourTimeField = new JTextField("HH", 2);
	JTextField startMinuteTimeField = new JTextField("MM", 2);
	JTextField endHourTimeField = new JTextField("HH", 2);
	JTextField endMinuteTimeField = new JTextField("MM", 2);
	JTextField startDateMonthField = new JTextField("MM", 2);
	JTextField startDateDayField = new JTextField("DD", 2);
	JTextField startDateYearField = new JTextField("YYYY", 3);
	JTextField endDateMonthField = new JTextField("MM", 2);
	JTextField endDateDayField = new JTextField("DD", 2);
	JTextField endDateYearField = new JTextField("YYYY", 3);
	JTextField locationField = new JTextField("", 20);
	JTextField fileField = new JTextField("", 20);
	JTextArea descriptionArea = new JTextArea("", 8, 15);
	JTextArea commentsArea = new JTextArea("", 8, 15);
	JTextArea resourcesArea = new JTextArea("", 6, 20);
	JTextArea resultArea = new JTextArea("", 50,100);
	JScrollPane resultPane = new JScrollPane(resultArea);
	JScrollPane descriptionPane = new JScrollPane(descriptionArea);
	JScrollPane commentsPane = new JScrollPane(commentsArea);
	JScrollPane resourcesPane = new JScrollPane(resourcesArea);
	
	JButton createButton = new JButton("Create Event");
	JButton clearButton = new JButton("Clear fields");
	
	String[] timeStrings = {"AM", "PM"};
	JComboBox startTimeList = new JComboBox(timeStrings);
	JComboBox endTimeList = new JComboBox(timeStrings);
	
	String[] timeZones = {"Hawaii Standard Time", "Alaska Daylight Time", 
								 "Pacific Daylight Time", "Mountain Daylight Time", 
								 "Central Daylight Time", "Eastern Daylight Time"};
	JComboBox timeZoneList = new JComboBox(timeZones);

	String[] priorityStrings = {"None", "Low", "High"};
	JComboBox priorityList = new JComboBox(priorityStrings);

	Container contentPane = this.getContentPane();
   SpringLayout layout = new SpringLayout();
	Font f = nameLabel.getFont();
	
	String name;
	int startHourTime;
	int startMinuteTime;
	String startTimeString;
	int endHourTime;
	int endMinuteTime;
	String endTimeString;
	String timeZoneString;
	int startMonth;
	int startDay;
	int startYear;
	int endMonth;
	int endDay;
	int endYear;
	String location;
	String description;
	String comments;
	String priority;
	String resources;
	String fileName;
	Color background = new Color(199,237,255);
	
	boolean validEvent = true;
	boolean validStartHourTime = true;
	boolean validStartMinuteTime = true;
	boolean validEndHourTime = true;
	boolean validEndMinuteTime = true;
	boolean validStartDay = true;
	boolean validStartMonth = true;
	boolean validStartYear = true;
	boolean validEndDay = true;
	boolean validEndMonth = true;
	boolean validEndYear = true;
	boolean validName = true;
	boolean allValid = true;


   public void init() {
		//Set size of applet, background color, and add all components
	   setSize(470, 700);
		contentPane.setBackground(background);
   	contentPane.setLayout(layout);
		nameLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
      contentPane.add(nameLabel);
      contentPane.add(nameField);
		timeLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(timeLabel);
		contentPane.add(startHourTimeField);
		contentPane.add(colonLabel1);
		contentPane.add(startMinuteTimeField);
		contentPane.add(startTimeList);
		contentPane.add(toLabel1);
		contentPane.add(endHourTimeField);
		contentPane.add(colonLabel2);
		contentPane.add(endMinuteTimeField);
		contentPane.add(endTimeList);
		timeZoneLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(timeZoneLabel);
		contentPane.add(timeZoneList);
		dateLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(dateLabel);
		contentPane.add(startDateMonthField);
		contentPane.add(slashLabel1);
		contentPane.add(startDateDayField);
		contentPane.add(slashLabel2);
		contentPane.add(startDateYearField);
		contentPane.add(toLabel2);
		contentPane.add(endDateMonthField);
		contentPane.add(slashLabel3);
		contentPane.add(endDateDayField);
		contentPane.add(slashLabel4);
		contentPane.add(endDateYearField);
		locationLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(locationLabel);
		contentPane.add(locationField);
		descriptionLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(descriptionLabel);
		contentPane.add(descriptionPane);
		commentsLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(commentsLabel);
		contentPane.add(commentsPane);
		priorityLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(priorityLabel);
		contentPane.add(priorityList);
		resourcesLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(resourcesLabel);
		contentPane.add(resourcesPane);
		fileLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
		contentPane.add(fileLabel);
		contentPane.add(fileField);
		contentPane.add(createButton);
		contentPane.add(clearButton);
		createButton.addActionListener(this);
		createButton.setActionCommand("create");	
		clearButton.addActionListener(this);
		clearButton.setActionCommand("clear");
		
		//Set layout components
		layout.putConstraint(SpringLayout.WEST, nameLabel, 20, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, nameLabel, 24, SpringLayout.NORTH, contentPane);
		layout.putConstraint(SpringLayout.WEST, nameField, 5, SpringLayout.EAST, nameLabel);
		layout.putConstraint(SpringLayout.NORTH, nameField, 20, SpringLayout.NORTH, contentPane);

		layout.putConstraint(SpringLayout.WEST, timeLabel, 20, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, timeLabel, 24, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, startHourTimeField, 7, SpringLayout.EAST, timeLabel);
		layout.putConstraint(SpringLayout.NORTH, startHourTimeField, 20, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, colonLabel1, 2, SpringLayout.EAST, startHourTimeField);
		layout.putConstraint(SpringLayout.NORTH, colonLabel1, 24, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, startMinuteTimeField, 2, SpringLayout.EAST, colonLabel1);
		layout.putConstraint(SpringLayout.NORTH, startMinuteTimeField, 20, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, startTimeList, 5, SpringLayout.EAST, startMinuteTimeField);
		layout.putConstraint(SpringLayout.NORTH, startTimeList, 22, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, toLabel1, 5, SpringLayout.EAST, startTimeList);
		layout.putConstraint(SpringLayout.NORTH, toLabel1, 24, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, endHourTimeField, 5, SpringLayout.EAST, toLabel1);
		layout.putConstraint(SpringLayout.NORTH, endHourTimeField, 20, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, colonLabel2, 2, SpringLayout.EAST, endHourTimeField);
		layout.putConstraint(SpringLayout.NORTH, colonLabel2, 24, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, endMinuteTimeField, 2, SpringLayout.EAST, colonLabel2);
		layout.putConstraint(SpringLayout.NORTH, endMinuteTimeField, 20, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, endTimeList, 5, SpringLayout.EAST, endMinuteTimeField);
		layout.putConstraint(SpringLayout.NORTH, endTimeList, 22, SpringLayout.SOUTH, nameLabel);
		
		layout.putConstraint(SpringLayout.WEST, timeZoneLabel, 20, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, timeZoneLabel, 40, SpringLayout.SOUTH, timeLabel);
		layout.putConstraint(SpringLayout.WEST, timeZoneList, 5, SpringLayout.EAST, timeZoneLabel);
		layout.putConstraint(SpringLayout.NORTH, timeZoneList, 35, SpringLayout.SOUTH, timeLabel);
		
		layout.putConstraint(SpringLayout.WEST, dateLabel, 20, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, dateLabel, 35, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, startDateMonthField, 5, SpringLayout.EAST, dateLabel);
		layout.putConstraint(SpringLayout.NORTH, startDateMonthField, 30, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, slashLabel1, 2, SpringLayout.EAST, startDateMonthField);
		layout.putConstraint(SpringLayout.NORTH, slashLabel1, 35, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, startDateDayField, 2, SpringLayout.EAST, slashLabel1);
		layout.putConstraint(SpringLayout.NORTH, startDateDayField, 30, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, slashLabel2, 2, SpringLayout.EAST, startDateDayField);
		layout.putConstraint(SpringLayout.NORTH, slashLabel2, 35, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, startDateYearField, 2, SpringLayout.EAST, slashLabel2);
		layout.putConstraint(SpringLayout.NORTH, startDateYearField, 30, SpringLayout.SOUTH, timeZoneLabel); 
		layout.putConstraint(SpringLayout.WEST, toLabel2, 5, SpringLayout.EAST, startDateYearField);
		layout.putConstraint(SpringLayout.NORTH, toLabel2, 35, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, endDateMonthField, 5, SpringLayout.EAST, toLabel2);
		layout.putConstraint(SpringLayout.NORTH, endDateMonthField, 30, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, slashLabel3, 2, SpringLayout.EAST, endDateMonthField);
		layout.putConstraint(SpringLayout.NORTH, slashLabel3, 35, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, endDateDayField, 2, SpringLayout.EAST, slashLabel3);
		layout.putConstraint(SpringLayout.NORTH, endDateDayField, 30, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, slashLabel4, 2, SpringLayout.EAST, endDateDayField);
		layout.putConstraint(SpringLayout.NORTH, slashLabel4, 35, SpringLayout.SOUTH, timeZoneLabel);
		layout.putConstraint(SpringLayout.WEST, endDateYearField, 2, SpringLayout.EAST, slashLabel4);
		layout.putConstraint(SpringLayout.NORTH, endDateYearField, 30, SpringLayout.SOUTH, timeZoneLabel); 

      layout.putConstraint(SpringLayout.WEST, locationLabel, 20, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, locationLabel, 24, SpringLayout.SOUTH, dateLabel);
		layout.putConstraint(SpringLayout.WEST, locationField, 5, SpringLayout.EAST, locationLabel);
		layout.putConstraint(SpringLayout.NORTH, locationField, 20, SpringLayout.SOUTH, dateLabel);

		layout.putConstraint(SpringLayout.WEST, descriptionLabel, 70, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, descriptionLabel, 25, SpringLayout.SOUTH, locationLabel);
		layout.putConstraint(SpringLayout.WEST, descriptionPane, 20, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, descriptionPane, 45, SpringLayout.SOUTH, locationLabel);
		
		layout.putConstraint(SpringLayout.WEST, commentsLabel, 75, SpringLayout.EAST, descriptionPane);
		layout.putConstraint(SpringLayout.NORTH, commentsLabel, 25, SpringLayout.SOUTH, locationLabel);
		layout.putConstraint(SpringLayout.WEST, commentsPane, 25, SpringLayout.EAST, descriptionPane);
		layout.putConstraint(SpringLayout.NORTH, commentsPane, 45, SpringLayout.SOUTH, locationLabel);
		
		layout.putConstraint(SpringLayout.WEST, priorityLabel, 130, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, priorityLabel, 24, SpringLayout.SOUTH, commentsPane);
		layout.putConstraint(SpringLayout.WEST, priorityList, 5, SpringLayout.EAST, priorityLabel);
		layout.putConstraint(SpringLayout.NORTH, priorityList, 20, SpringLayout.SOUTH, commentsPane);
		
		layout.putConstraint(SpringLayout.WEST, resourcesLabel, 20, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, resourcesLabel, 20, SpringLayout.SOUTH, priorityLabel);
		layout.putConstraint(SpringLayout.WEST, resourcesPane, 5, SpringLayout.EAST, resourcesLabel);
		layout.putConstraint(SpringLayout.NORTH, resourcesPane, 20, SpringLayout.SOUTH, priorityLabel);
		
		layout.putConstraint(SpringLayout.WEST, fileLabel, 20, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, fileLabel, 24, SpringLayout.SOUTH, resourcesPane);
		layout.putConstraint(SpringLayout.WEST, fileField, 5, SpringLayout.EAST, fileLabel);
		layout.putConstraint(SpringLayout.NORTH, fileField, 20, SpringLayout.SOUTH, resourcesPane);

		layout.putConstraint(SpringLayout.WEST, createButton, 80, SpringLayout.WEST, contentPane);
		layout.putConstraint(SpringLayout.NORTH, createButton, 20, SpringLayout.SOUTH, fileLabel);
		
		layout.putConstraint(SpringLayout.WEST, clearButton, 150, SpringLayout.WEST, createButton);
		layout.putConstraint(SpringLayout.NORTH, clearButton, 20, SpringLayout.SOUTH, fileLabel);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		//If the user clicks the "Create Event" button
		if (e.getActionCommand().equals("create"))
		{
			//Get all text from fields
			this.name = nameField.getText();
			
			//Make sure there are no empty fields or characters in the fields taking numbers
			try
			{
				this.startHourTime = Integer.parseInt(startHourTimeField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The start hour time you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.startMinuteTime = Integer.parseInt(startMinuteTimeField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The start minute time you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.endHourTime = Integer.parseInt(endHourTimeField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The end hour time you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.endMinuteTime = Integer.parseInt(endMinuteTimeField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The end minute time you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.startMonth = Integer.parseInt(startDateMonthField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The start month you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.startDay = Integer.parseInt(startDateDayField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The start day you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.startYear = Integer.parseInt(startDateYearField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The start year you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.endMonth = Integer.parseInt(endDateMonthField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The end month you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.endDay = Integer.parseInt(endDateDayField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The end day you entered was not valid.\n");
				this.allValid = false;
			}
			
			try
			{
				this.endYear = Integer.parseInt(endDateYearField.getText());
			}
			catch (Exception ex)
			{
				descriptionArea.append("The end year you entered was not valid.\n");
				this.allValid = false;
			}
			
			this.location = locationField.getText();
			this.description = descriptionArea.getText();
			this.comments = commentsArea.getText();
			this.resources = resourcesArea.getText();
			this.fileName = fileField.getText();
			this.startTimeString = (startTimeList.getSelectedItem()).toString();
			this.endTimeString = (endTimeList.getSelectedItem()).toString();
			this.timeZoneString = (timeZoneList.getSelectedItem()).toString();
			this.priority = (priorityList.getSelectedItem()).toString();
		
			//Make sure all fields have valid contents
			if (this.allValid)
			{
				this.validateName();
				if (!this.validName)
				{
					descriptionArea.append("The name you entered was not valid.\n");
				}
		
				this.validateStartHour();
				this.validateStartMinute();
				this.validateEndHour();
				this.validateEndMinute();
			
				if (!this.validStartHourTime)
				{
					this.allValid = false;
					descriptionArea.append("The hour of the start time is not valid.\n");
				}
			
				if (!this.validStartMinuteTime)
				{
					this.allValid = false;
					descriptionArea.append("The minute of the start time is not valid.\n");
				}
			
				if (!this.validEndHourTime)
				{
					this.allValid = false;
					descriptionArea.append("The hour of the end time is not valid.\n");
				}
			
				if (!this.validEndMinuteTime)
				{
					this.allValid = false;
					descriptionArea.append("The minute of the end time is not valid.\n");
				}
		
				this.validateStartYear();
				this.validateStartMonth();
			
				if (this.validStartYear)
				{
					if (this.validStartMonth)
					{
						this.validateStartDay();
						
						if (!this.validStartDay)
						{
							this.allValid = false;
							descriptionArea.append("The starting day you entered was not valid.\n");
						}
					}
				
					else
					{
						this.allValid = false;
						descriptionArea.append("The starting month you entered was not valid.\n");
					}
				}
		
				else
				{
					this.allValid = false;
					descriptionArea.append("The starting year you entered was not valid.\n");
				
					if (!this.validStartMonth)
					{
						descriptionArea.append("The starting month you entered was not valid.\n");
					}
				}
			
				this.validateEndYear();
				this.validateEndMonth();
			
				if (this.validEndYear)
				{
					if (this.validEndMonth)
					{
						this.validateEndDay();
						
						if (!this.validEndDay)
						{
							this.allValid = false;
							descriptionArea.append("The ending day you entered was not valid.\n");
						}
					}
				
					else
					{
						this.allValid = false;
						descriptionArea.append("The ending month you entered was not valid.\n");
					}
				}
		
				else
				{
					this.allValid = false;
					descriptionArea.append("The ending year you entered was not valid.\n");
				
					if (!this.validEndMonth)
					{
						descriptionArea.append("The ending month you entered was not valid.\n");
					}
				}
			
				if (!this.endTimeGreaterThanStart())
				{
					this.allValid = false;
					descriptionArea.append("This event's ending time must be after it's starting time.\n");
				}
			
				if (location.length() == 0)
				{
					location = " ";
				}
			
				if (description.length() == 0)
				{
					description = " ";
				}
			
				if (comments.length() == 0)
				{
					comments = " ";
				}
			
				if (resources.length() == 0)
				{
					resources = " ";
				}
				
				if (fileName.length() == 0)
				{
					fileName = "";
				}
			}
			
			//If all fields were valid, make the .ics file and append results to results text area
			if (this.allValid)
			{
				this.setSize(700,900);
				this.add(resultPane);
				layout.putConstraint(SpringLayout.WEST, resultPane, 50, SpringLayout.EAST, endTimeList);
				resultArea.append("Name: " + name);
				resultArea.append("\nStart time: " + startHourTime + ":" + startMinuteTime + " " + startTimeString);
				resultArea.append("\nEnd time: " + endHourTime + ":" + endMinuteTime + " " +endTimeString);
				resultArea.append("\nTime zone: " + timeZoneString);
				resultArea.append("\nStart date: " + startMonth + "/" + startDay + "/" + startYear);
				resultArea.append("\nEnd date: " + endMonth + "/" + endDay + "/" + endYear);
				resultArea.append("\nLocation: " + location);
				resultArea.append("\nDescription: " + description);
				resultArea.append("\nComments: " + comments);
				resultArea.append("\nPriority: " + priority);
				resultArea.append("\nResources: " + resources);
				resultArea.append("\nFile name: " + fileName);
				String message = ICSFileCreatorFinal.createFiles(name, startMonth, startDay, startYear, endMonth, endDay, endYear, startHourTime,
                          startMinuteTime, startTimeString, endHourTime, endMinuteTime, endTimeString,
                          description, location, timeZoneString, comments, resources, priority, fileName);
																			
				resultArea.append("\n" + message);
			}
		}
		
		//If the user clicks the "clear fields" button, reinitialize all fields
		else if (e.getActionCommand().equals("clear"))
		{
			nameField.setText("");
			startHourTimeField.setText("HH");
			startMinuteTimeField.setText("MM");
			endHourTimeField.setText("HH");
			endMinuteTimeField.setText("MM");
			startDateMonthField.setText("MM");
			startDateDayField.setText("DD");
			startDateYearField.setText("YYYY");
			endDateMonthField.setText("MM");
			endDateDayField.setText("DD");
			endDateYearField.setText("YYYY");
			locationField.setText("");
			descriptionArea.setText("");
			commentsArea.setText("");
			resourcesArea.setText("");
			resultArea.setText("");
			fileField.setText("");
		}
	}
	

	/**
	 * endTimeGreaterThanStart()
	 * 
	 * Checks to see if the ending event time is after the
	 * starting time
	 * 
	 * @return	True if the end time is after the start time, false if not	
	 */
   public boolean endTimeGreaterThanStart()
	{
		boolean greater = true;
	
		if (this.endYear < this.startYear)
		{
			greater = false;
		}
		
		else if (this.endYear > this.startYear)
		{
			greater = true;
		}
		
		else if (this.endYear == this.startYear)
		{
			if (this.endMonth < this.startMonth)
			{
				greater = false;
			}
			
			else if (this.endMonth > this.startMonth)
			{
				greater = true;
			}
			
			else if (this.endMonth == this.startMonth)
			{
				if (this.endDay < this.startDay)
				{
					greater = false;
				}
				
				else if (this.endDay > this.startDay)
				{
					greater = true;
				}
				
				else if (this.endDay == this.startDay)
				{
					if (this.endTimeString.equals("AM") && this.startTimeString.equals("PM"))
					{
						greater = false;
					}
					
					else if (this.endTimeString.equals("PM") && this.startTimeString.equals("AM"))
					{
						greater = true;
					}
					
					else if (this.endTimeString.equals(this.startTimeString))
					{
						if (this.endHourTime < this.startHourTime)
						{
							greater = false;
						}
						
						else if (this.endHourTime > this.startHourTime)
						{
							greater = true;
						}
						
						else if (this.endHourTime == this.startHourTime)
						{
							if (this.endMinuteTime <= this.startHourTime)
							{
								greater = false;
							}
							
							else if (this.endMinuteTime > this.startHourTime)
							{
								greater = true;
							}
						}
					}
				}
			}
		}
		
		return greater;
	}

	/**
	 * validateStartMonth()
	 * 
	 * Checks for a valid starting month
	 * 
	 * @return	void	
	 */
	public void validateStartMonth()
	{
		if (this.startMonth >= 1 && this.startMonth <= 12)
		{
			this.validStartMonth = true;
		}
		
		else
		{
			this.validStartMonth = false;
		}
	}
	
	/**
	 * validateStartDay()
	 * 
	 * Checks for a valid starting day
	 * 
	 * @return	void	
	 */
	public void validateStartDay()
	{
		boolean isLeapYear = false;
	
		if (this.startMonth == 1 || this.startMonth == 3 || this.startMonth == 5 || this.startMonth == 7 || this.startMonth == 8 || this.startMonth == 10 || this.startMonth == 12)
		{
			if (this.startDay >= 1 && this.startDay <= 31)
			{
				this.validStartDay = true;
			}
		}
		
		else if (this.startMonth == 4 || this.startMonth == 6 || this.startMonth == 9 || this.startMonth == 11)
		{
			if (this.startDay >= 1 && this.startDay <= 30)
			{
				this.validStartDay = true;
			}
		}
		
		else if (this.startMonth == 2)
		{
			if (this.startYear % 400 == 0)
			{
				isLeapYear = true;
			}
			
			else if (this.startYear % 100 == 0)
			{
				isLeapYear = false;
			}
			
			else if (this.startYear % 4 == 0)
			{
				isLeapYear = true;
			}
			
			if (isLeapYear)
			{
				if (this.startDay >= 1 && this.startDay <= 29)
				{
					this.validStartDay = true;
				}
			}
			
			else if (!isLeapYear)
			{
				if (this.startDay >= 1 && this.startDay <= 28)
				{
					this.validStartDay = true;
				}
			}
		}
			
		else
		{
			this.validStartDay = false;
		}
	}
	
	/**
	 * validateStartYear()
	 * 
	 * Checks for a valid starting year
	 * 
	 * @return	void	
	 */
	public void validateStartYear()
	{
		if (this.startYear >= 2012)
		{
			this.validStartYear = true;
		}
	
		else
		{
			this.validStartYear = false;
		}
	}
	
	/**
	 * validateEndMonth()
	 * 
	 * Checks for a valid ending month
	 * 
	 * @return	void	
	 */
	public void validateEndMonth()
	{
		if (this.endMonth >= 1 && this.endMonth <= 12)
		{
			this.validEndMonth = true;
		}
		
		else
		{
			this.validEndMonth = false;
		}
	}
	
	/**
	 * validateEndDay()
	 * 
	 * Checks for a valid ending day
	 * 
	 * @return	void	
	 */
	public void validateEndDay()
	{
		boolean isLeapYear = false;
	
		if (this.endMonth == 1 || this.endMonth == 3 || this.endMonth == 5 || this.endMonth == 7 || this.endMonth == 8 || this.endMonth == 10 || this.endMonth == 12)
		{
			if (this.endDay >= 1 && this.endDay <= 31)
			{
				this.validEndDay = true;
			}
		}
		
		else if (this.endMonth == 4 || this.endMonth == 6 || this.endMonth == 9 || this.endMonth == 11)
		{
			if (this.endDay >= 1 && this.endDay <= 30)
			{
				this.validEndDay = true;
			}
		}
		
		else if (this.endMonth == 2)
		{
			if (this.endYear % 400 == 0)
			{
				isLeapYear = true;
			}
			
			else if (this.endYear % 100 == 0)
			{
				isLeapYear = false;
			}
			
			else if (this.endYear % 4 == 0)
			{
				isLeapYear = true;
			}
			
			if (isLeapYear)
			{
				if (this.endDay >= 1 && this.endDay <= 29)
				{
					this.validEndDay = true;
				}
			}
			
			else if (!isLeapYear)
			{
				if (this.endDay >= 1 && this.endDay <= 28)
				{
					this.validEndDay = true;
				}
			}
		}
			
		else
		{
			this.validEndDay = false;
		}
	}
	
	/**
	 * validateEndYear()
	 * 
	 * Checks for a valid ending year
	 * 
	 * @return	void	
	 */
	public void validateEndYear()
	{
		if (this.endYear >= 2012)
		{
			this.validEndYear = true;
		}
	
		else
		{
			this.validEndYear = false;
		}
	}
	
	/**
	 * validateStartHour()
	 * 
	 * Checks for a valid start hour
	 * 
	 * @return	void	
	 */
	public void validateStartHour()
	{
		if (this.startHourTime >= 1 && this.startHourTime <= 12)
		{
			this.validStartHourTime = true;
		}
		
		else
		{
			this.validStartHourTime = false;
		}
	}
	
	/**
	 * validateStartMinute()
	 * 
	 * Checks for a valid starting minute
	 * 
	 * @return	void	
	 */
	public void validateStartMinute()
	{
		if (this.startMinuteTime >= 0 && this.startMinuteTime <= 59)
		{
			this.validStartMinuteTime = true;
		}
		
		else
		{
			this.validStartMinuteTime = false;
		}
	}
	
	/**
	 * validateEndHour()
	 * 
	 * Checks for a valid ending hour
	 * 
	 * @return	void	
	 */
	public void validateEndHour()
	{
		if (this.endHourTime >= 1 && this.endHourTime <= 12)
		{
			this.validEndHourTime = true;
		}
		
		else
		{
			this.validEndHourTime = false;
		}
	}
	
	/**
	 * validateEndMinute()
	 * 
	 * Checks for a valid ending minute
	 * 
	 * @return	void	
	 */
	public void validateEndMinute()
	{
		if (this.endMinuteTime >= 0 && this.endMinuteTime <= 59)
		{
			this.validEndMinuteTime = true;
		}
		
		else
		{
			this.validEndMinuteTime = false;
		}
	}
	
	/**
	 * validateName()
	 * 
	 * Checks to see if the name field has been left blank
	 * 
	 * @return	void	
	 */
	public void validateName()
	{
		if (this.name.length() > 0)
		{
			validName = true;
		}
		
		else
		{
			validName = false;
		}
	}

}